package com.bee.mydiary.camera;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.bee.mydiary.R;

public class ShowPicActivity extends Activity {
	private String TAG = "ShowPicActivity";
	private String PATH = "path";
	private String IMG = "img";
	private String NAME = "name";
	private String TIME = "time";
	private ListView mCameraView;
	private ImageServer mImageServer;
	private ArrayList<HashMap<String, Object>> camera_map;
	private List<HashMap<String, String>> mCameraList;
	private SimpleAdapter cameraSimpleAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.v(TAG, "ShowPicActivity onCreate()");
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.camera_showpic);
		mImageServer = new ImageServer(this);
		mCameraView = (ListView) findViewById(R.id.cameraview);
		camera_map = new ArrayList<HashMap<String, Object>>();
		mCameraList = new ArrayList<HashMap<String, String>>();
	}

	@Override
	protected void onResume() {
		Log.v(TAG, "ShowPicActivity onResume()");
		// TODO Auto-generated method stub
		super.onResume();
		mCameraList = mImageServer.getImages();
		addPic();
		mCameraView.setAdapter(cameraSimpleAdapter);

	}
	@Override
	protected void onStop() {
		Log.v(TAG, "ShowPicActivity onStop()");
		// TODO Auto-generated method stub
		super.onStop();
	}
	
	@Override
	protected void onDestroy() {
		Log.v(TAG, "ShowPicActivity onDestroy()");
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	public void addPic() {
		int pic_totle = mImageServer.getNum();
		Log.v(TAG, "addPic pic_totle is " + pic_totle);
		if (pic_totle <= 0)
			return;
		for (int i = 0; i < pic_totle - 1; i++) {
			HashMap<String, Object> camera_item = new HashMap<String, Object>();
			String path = mCameraList.get(i).get(PATH);
			Log.v(TAG, "the path is " + path);
			String name = mCameraList.get(i).get(NAME);
			Uri uri = Uri.parse(path);
			camera_item.put(IMG, uri);
			camera_item.put(NAME, name);
			camera_item.put(TIME, "100");
			camera_map.add(camera_item);
		}
		cameraSimpleAdapter = new SimpleAdapter(this, camera_map, R.layout.camera_item,
				new String[] { IMG, NAME, TIME }, new int[] { R.id.img,
						R.id.name, R.id.time });
	}

}
